<?php

class Jhub1_View_Helper_Seotranslation extends Zend_View_Helper_Abstract {

    protected $_params;
    protected $_name;
/*
 * 
 * This class generates URL key to pull proper record off DB ( see Seo table and its content )
 * 
 * 
 * 
 * 
 * 
 */

    public function seotranslation($name) {
        $this->_name = $name;
        $logger = Zend_Registry::get('log');
        $this->_params = Zend_Controller_Front::getInstance()->getRequest()->getParams();
        $translate = $this->transl($this->makeURL());
        if ($translate == "") {
            $logger->err($name .  ' :  --has no translation for this URL--');
        }
        return $translate;
    }
    
    public function makeURL() {
          $urlpart =  "/" . $this->_params['controller'] . "/" . $this->_params['action'];
          $urlspart = "";
 #        Zend_Debug::dump($this->_params , 'QQQQQQQQQQQQQQQQQQqq');
          foreach ($this->_params as $key => $value) {
              if ($key != 'controller' && $key != 'action' && $key != 'module' && $key != 'error_handler') {
                  $urlspart .= "/" . $key . "/" . $value;
              }
          }
       return $urlpart . $urlspart;
    }

    public function transl($url) {
        $logger = Zend_Registry::get('log');
        $session = new Zend_Session_Namespace('GrandMarnier');
        $seo = new Application_Model_DbTable_Seo();
        $seo->setLanguage($session->userLanguage);
        $seoTransl = $seo->getTranslation($url, $this->_name);
        return $seoTransl;
    }
    
/*
    public function translold() {
        $logger = Zend_Registry::get('log');
        $session = new Zend_Session_Namespace('GrandMarnier');
        $translation = new Application_Model_DbTable_Translation();
        $translation->setLanguage($session->userLanguage);
        $transl = $translation->getAllTranslations();
#        Zend_Debug::dump($transl, '$transl', true);
        if (array_key_exists($this->_keyword, $transl)) {
            if ($transl[$this->_keyword] != "") {
                $logger->info($this->_keyword . ' : ' . $transl[$this->_keyword]);
                return $transl[$this->_keyword];
            } else {
                $logger->err($this->_keyword .  ' :  --no translation--');
                return $this->_keyword;
            }
        } else {
            $logger->err($this->_keyword . ' :  --no translation--');
            return $this->_keyword;
        }
    }

    // The default representation of the greeting. Let's be nice, by default.
    public function __toString() {
        return "";
    }
*/
}

#echo  $this->seotranslation('description'); (lang)
#echo  $this->seotranslation('xiti_rub');   (lang)
#echo  $this->seotranslation('xiti_page');
?>